package Utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

public class vcomcn {
	static Logger logger = Logger.getLogger(vcomcn.class);
	/**
	 * 生成发送短信的XML字符串内容
	 */
	public static String createSmsSendXml(Map<String, String> map) {
		StringPlus sp = new StringPlus();
		sp.append(String
				.format("<Group Login_Name=\"%s\" Login_Pwd=\"%s\" InterFaceID=\"\" OpKind=\"0\">",
						map.get("LOGIN_NAME"), map.get("PASSWORD")));
		sp.append(String.format("<E_Time>%s</E_Time>", map.get("START_TIME")));
		sp.append("<Item>");
		sp.append("<Task>");
		sp.append(String.format(
				"<Recive_Phone_Number>%s</Recive_Phone_Number>",
				map.get("MOBILE")));
		sp.append(String.format("<Content><![CDATA[%s]]></Content>",
				map.get("MESSAGE")));
		sp.append(String.format("<Search_ID>%s</Search_ID>", map.get("TASK_ID")));
		sp.append("</Task>");
		sp.append("</Item>");
		sp.append("</Group>");
		return sp.value();
	}
	
	public static long sendSms(String msg,String phone) {
		
		String taskId=GenerateRandNumHelper.generate(4)+phone;
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("LOGIN_NAME", "youbox");
		map.put("PASSWORD", MD5Helper.getMD5Str("ybld1401").toUpperCase());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		map.put("START_TIME", sdf.format(new Date()));
		map.put("MOBILE", phone);
		map.put("MESSAGE", msg);
		map.put("TASK_ID", taskId );
		String xml=createSmsSendXml(map);
		String response=Http.post("http://userinterface.vcomcn.com/Opration.aspx",
				xml);
		if(response.equals("00")){
			return Long.parseLong(taskId);
		}else{
			//短信发送失败
//			logger.info("[Error]vcomcn send fail response: "+response);
			return -1;
		}
	}
	
	public static long send720Sms(String msg,String phone) {
		
		String taskId=GenerateRandNumHelper.generate(4)+phone;
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("LOGIN_NAME", "fj720_01");
		map.put("PASSWORD", MD5Helper.getMD5Str("ab8888").toUpperCase());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		map.put("START_TIME", sdf.format(new Date()));
		map.put("MOBILE", phone);
		map.put("MESSAGE", msg);
		map.put("TASK_ID", taskId );
		String xml=createSmsSendXml(map);
		String response=Http.post("http://userinterface.vcomcn.com/Opration.aspx",
				xml);
//		String response=Http.post("http://www.vcomcn.cn/",
//				xml);
		if(response.equals("00")){
			return Long.parseLong(taskId);
		}else{
			//短信发送失败
//			logger.info("[Error]vcomcn send fail response: "+response);
			return -1;
		}
	}
	
	public static long sendYYSms(String msg,String phone) {
		String taskId=GenerateRandNumHelper.generate(4)+phone;
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("LOGIN_NAME", "yydz");
		map.put("PASSWORD", MD5Helper.getMD5Str("ab8888").toUpperCase());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		map.put("START_TIME", sdf.format(new Date()));
		map.put("MOBILE", phone);
		map.put("MESSAGE", msg);
		map.put("TASK_ID", taskId );
		String xml=createSmsSendXml(map);
		String response=Http.post("http://userinterface.vcomcn.com/Opration.aspx",
				xml);
//		String response=Http.post("http://www.vcomcn.cn/",
//				xml);
		if(response.equals("00")){
			return Long.parseLong(taskId);
		}else{
			//短信发送失败
//			logger.info("[Error]vcomcn send fail response: "+response);
			return -1;
		}
	}
}
